/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('commondriver', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model ActiveProductRequest {
  activeCode?: string(name='ActiveCode'),
  appId?: string(name='AppId'),
  commodityCode?: string(name='CommodityCode'),
  corpId?: string(name='CorpId'),
  itemCode?: string(name='ItemCode'),
  regionId?: string(name='RegionId'),
}

model ActiveProductResponseBody = {
  code?: string(name='Code'),
  data?: string(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model ActiveProductResponse = {
  headers: map[string]string(name='headers'),
  body: ActiveProductResponseBody(name='body'),
}

async function activeProductWithOptions(request: ActiveProductRequest, runtime: Util.RuntimeOptions): ActiveProductResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  if (!Util.isUnset(request.activeCode)) {
    body['ActiveCode'] = request.activeCode;
  }
  if (!Util.isUnset(request.appId)) {
    body['AppId'] = request.appId;
  }
  if (!Util.isUnset(request.commodityCode)) {
    body['CommodityCode'] = request.commodityCode;
  }
  if (!Util.isUnset(request.corpId)) {
    body['CorpId'] = request.corpId;
  }
  if (!Util.isUnset(request.itemCode)) {
    body['ItemCode'] = request.itemCode;
  }
  if (!Util.isUnset(request.regionId)) {
    body['RegionId'] = request.regionId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ActiveProduct',
    version = '2016-07-12',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function activeProduct(request: ActiveProductRequest): ActiveProductResponse {
  var runtime = new Util.RuntimeOptions{};
  return activeProductWithOptions(request, runtime);
}

model CreateOrderIapRequest {
  paramString?: string(name='ParamString'),
}

model CreateOrderIapResponseBody = {
  code?: string(name='Code'),
  data?: string(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model CreateOrderIapResponse = {
  headers: map[string]string(name='headers'),
  body: CreateOrderIapResponseBody(name='body'),
}

async function createOrderIapWithOptions(request: CreateOrderIapRequest, runtime: Util.RuntimeOptions): CreateOrderIapResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  if (!Util.isUnset(request.paramString)) {
    body['ParamString'] = request.paramString;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'CreateOrderIap',
    version = '2016-07-12',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function createOrderIap(request: CreateOrderIapRequest): CreateOrderIapResponse {
  var runtime = new Util.RuntimeOptions{};
  return createOrderIapWithOptions(request, runtime);
}

model GetInstanceIdsFromTokenRequest {
  fromApp?: string(name='FromApp', description='fromApp'),
  requestId?: string(name='RequestId', description='requestId'),
  token?: string(name='Token', description='token'),
}

model GetInstanceIdsFromTokenResponseBody = {
  code?: string(name='Code', description='code'),
  data?: string(name='Data', description='data'),
  i18nKey?: string(name='I18nKey', description='i18nKey'),
  message?: string(name='Message', description='message'),
  requestId?: string(name='RequestId', description='requestId'),
  success?: boolean(name='Success', description='success'),
}

model GetInstanceIdsFromTokenResponse = {
  headers: map[string]string(name='headers'),
  body: GetInstanceIdsFromTokenResponseBody(name='body'),
}

async function getInstanceIdsFromTokenWithOptions(request: GetInstanceIdsFromTokenRequest, runtime: Util.RuntimeOptions): GetInstanceIdsFromTokenResponse {
  Util.validateModel(request);
  var query = OpenApiUtil.query(Util.toMap(request));
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetInstanceIdsFromToken',
    version = '2016-07-12',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'GET',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getInstanceIdsFromToken(request: GetInstanceIdsFromTokenRequest): GetInstanceIdsFromTokenResponse {
  var runtime = new Util.RuntimeOptions{};
  return getInstanceIdsFromTokenWithOptions(request, runtime);
}

model GetPlanItemSpecificationRequest {
  accessKey?: string(name='AccessKey'),
  buyerId?: string(name='BuyerId'),
  childId?: string(name='ChildId'),
  clientToken?: string(name='ClientToken'),
  fromApp?: string(name='FromApp'),
  payerId?: string(name='PayerId'),
  planItemId?: string(name='PlanItemId'),
  secretKey?: string(name='SecretKey'),
  userId?: string(name='UserId'),
}

model GetPlanItemSpecificationResponseBody = {
  code?: string(name='Code'),
  data?: string(name='Data'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model GetPlanItemSpecificationResponse = {
  headers: map[string]string(name='headers'),
  body: GetPlanItemSpecificationResponseBody(name='body'),
}

async function getPlanItemSpecificationWithOptions(request: GetPlanItemSpecificationRequest, runtime: Util.RuntimeOptions): GetPlanItemSpecificationResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.accessKey)) {
    query['AccessKey'] = request.accessKey;
  }
  if (!Util.isUnset(request.buyerId)) {
    query['BuyerId'] = request.buyerId;
  }
  if (!Util.isUnset(request.childId)) {
    query['ChildId'] = request.childId;
  }
  if (!Util.isUnset(request.clientToken)) {
    query['ClientToken'] = request.clientToken;
  }
  if (!Util.isUnset(request.fromApp)) {
    query['FromApp'] = request.fromApp;
  }
  if (!Util.isUnset(request.payerId)) {
    query['PayerId'] = request.payerId;
  }
  if (!Util.isUnset(request.planItemId)) {
    query['PlanItemId'] = request.planItemId;
  }
  if (!Util.isUnset(request.secretKey)) {
    query['SecretKey'] = request.secretKey;
  }
  if (!Util.isUnset(request.userId)) {
    query['UserId'] = request.userId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetPlanItemSpecification',
    version = '2016-07-12',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getPlanItemSpecification(request: GetPlanItemSpecificationRequest): GetPlanItemSpecificationResponse {
  var runtime = new Util.RuntimeOptions{};
  return getPlanItemSpecificationWithOptions(request, runtime);
}

model GetPlanSpecificationRequest {
  accessKey?: string(name='AccessKey'),
  buyerId?: string(name='BuyerId'),
  childId?: string(name='ChildId'),
  clientToken?: string(name='ClientToken'),
  fromApp?: string(name='FromApp'),
  needItemSpecification?: boolean(name='NeedItemSpecification'),
  payerId?: string(name='PayerId'),
  planCode?: string(name='PlanCode'),
  planId?: long(name='PlanId'),
  regionCode?: string(name='RegionCode'),
  secretKey?: string(name='SecretKey'),
  userId?: string(name='UserId'),
}

model GetPlanSpecificationResponseBody = {
  code?: string(name='Code'),
  data?: string(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  success?: string(name='Success'),
}

model GetPlanSpecificationResponse = {
  headers: map[string]string(name='headers'),
  body: GetPlanSpecificationResponseBody(name='body'),
}

async function getPlanSpecificationWithOptions(request: GetPlanSpecificationRequest, runtime: Util.RuntimeOptions): GetPlanSpecificationResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.accessKey)) {
    query['AccessKey'] = request.accessKey;
  }
  if (!Util.isUnset(request.buyerId)) {
    query['BuyerId'] = request.buyerId;
  }
  if (!Util.isUnset(request.childId)) {
    query['ChildId'] = request.childId;
  }
  if (!Util.isUnset(request.clientToken)) {
    query['ClientToken'] = request.clientToken;
  }
  if (!Util.isUnset(request.fromApp)) {
    query['FromApp'] = request.fromApp;
  }
  if (!Util.isUnset(request.needItemSpecification)) {
    query['NeedItemSpecification'] = request.needItemSpecification;
  }
  if (!Util.isUnset(request.payerId)) {
    query['PayerId'] = request.payerId;
  }
  if (!Util.isUnset(request.planCode)) {
    query['PlanCode'] = request.planCode;
  }
  if (!Util.isUnset(request.planId)) {
    query['PlanId'] = request.planId;
  }
  if (!Util.isUnset(request.regionCode)) {
    query['RegionCode'] = request.regionCode;
  }
  if (!Util.isUnset(request.secretKey)) {
    query['SecretKey'] = request.secretKey;
  }
  if (!Util.isUnset(request.userId)) {
    query['UserId'] = request.userId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetPlanSpecification',
    version = '2016-07-12',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getPlanSpecification(request: GetPlanSpecificationRequest): GetPlanSpecificationResponse {
  var runtime = new Util.RuntimeOptions{};
  return getPlanSpecificationWithOptions(request, runtime);
}

model GetSpecificationsRequest {
  paramStr?: string(name='paramStr'),
}

model GetSpecificationsResponseBody = {
  code?: string(name='Code'),
  data?: string(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model GetSpecificationsResponse = {
  headers: map[string]string(name='headers'),
  body: GetSpecificationsResponseBody(name='body'),
}

async function getSpecificationsWithOptions(request: GetSpecificationsRequest, runtime: Util.RuntimeOptions): GetSpecificationsResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.paramStr)) {
    query['paramStr'] = request.paramStr;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetSpecifications',
    version = '2016-07-12',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getSpecifications(request: GetSpecificationsRequest): GetSpecificationsResponse {
  var runtime = new Util.RuntimeOptions{};
  return getSpecificationsWithOptions(request, runtime);
}

model GlobalSyncSubDataRequest {
  paramStr?: string(name='paramStr'),
}

model GlobalSyncSubDataResponseBody = {
  code?: string(name='Code'),
  data?: string(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model GlobalSyncSubDataResponse = {
  headers: map[string]string(name='headers'),
  body: GlobalSyncSubDataResponseBody(name='body'),
}

async function globalSyncSubDataWithOptions(request: GlobalSyncSubDataRequest, runtime: Util.RuntimeOptions): GlobalSyncSubDataResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.paramStr)) {
    query['paramStr'] = request.paramStr;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GlobalSyncSubData',
    version = '2016-07-12',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function globalSyncSubData(request: GlobalSyncSubDataRequest): GlobalSyncSubDataResponse {
  var runtime = new Util.RuntimeOptions{};
  return globalSyncSubDataWithOptions(request, runtime);
}

model GlobalSyncSubReleaseRequest {
  paramStr?: string(name='paramStr'),
}

model GlobalSyncSubReleaseResponseBody = {
  code?: string(name='Code'),
  data?: string(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model GlobalSyncSubReleaseResponse = {
  headers: map[string]string(name='headers'),
  body: GlobalSyncSubReleaseResponseBody(name='body'),
}

async function globalSyncSubReleaseWithOptions(request: GlobalSyncSubReleaseRequest, runtime: Util.RuntimeOptions): GlobalSyncSubReleaseResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.paramStr)) {
    query['paramStr'] = request.paramStr;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GlobalSyncSubRelease',
    version = '2016-07-12',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function globalSyncSubRelease(request: GlobalSyncSubReleaseRequest): GlobalSyncSubReleaseResponse {
  var runtime = new Util.RuntimeOptions{};
  return globalSyncSubReleaseWithOptions(request, runtime);
}

model HostBindRequest {
  param?: string(name='Param'),
}

model HostBindResponseBody = {
  code?: string(name='Code'),
  data?: string(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model HostBindResponse = {
  headers: map[string]string(name='headers'),
  body: HostBindResponseBody(name='body'),
}

async function hostBindWithOptions(request: HostBindRequest, runtime: Util.RuntimeOptions): HostBindResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.param)) {
    query['Param'] = request.param;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'HostBind',
    version = '2016-07-12',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function hostBind(request: HostBindRequest): HostBindResponse {
  var runtime = new Util.RuntimeOptions{};
  return hostBindWithOptions(request, runtime);
}

model PutInstanceIdsToTokenRequest {
  commodityCode?: string(name='CommodityCode', description='commodityCode'),
  fromApp?: string(name='FromApp', description='fromApp'),
  requestId?: string(name='RequestId', description='requestId'),
  token?: string(name='Token', description='token'),
  body?: string(name='body', description='instanceIdStr'),
}

model PutInstanceIdsToTokenResponseBody = {
  code?: string(name='Code', description='code'),
  data?: string(name='Data', description='data'),
  i18nKey?: string(name='I18nKey', description='i18nKey'),
  message?: string(name='Message', description='message'),
  requestId?: string(name='RequestId', description='requestId'),
  success?: boolean(name='Success', description='success'),
}

model PutInstanceIdsToTokenResponse = {
  headers: map[string]string(name='headers'),
  body: PutInstanceIdsToTokenResponseBody(name='body'),
}

async function putInstanceIdsToTokenWithOptions(request: PutInstanceIdsToTokenRequest, runtime: Util.RuntimeOptions): PutInstanceIdsToTokenResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.commodityCode)) {
    query['CommodityCode'] = request.commodityCode;
  }
  if (!Util.isUnset(request.fromApp)) {
    query['FromApp'] = request.fromApp;
  }
  if (!Util.isUnset(request.requestId)) {
    query['RequestId'] = request.requestId;
  }
  if (!Util.isUnset(request.token)) {
    query['Token'] = request.token;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = request.body,
  };
  var params = new OpenApi.Params{
    action = 'PutInstanceIdsToToken',
    version = '2016-07-12',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function putInstanceIdsToToken(request: PutInstanceIdsToTokenRequest): PutInstanceIdsToTokenResponse {
  var runtime = new Util.RuntimeOptions{};
  return putInstanceIdsToTokenWithOptions(request, runtime);
}

model QueryHostRequest {
  param?: string(name='Param'),
}

model QueryHostResponseBody = {
  code?: string(name='Code'),
  data?: string(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model QueryHostResponse = {
  headers: map[string]string(name='headers'),
  body: QueryHostResponseBody(name='body'),
}

async function queryHostWithOptions(request: QueryHostRequest, runtime: Util.RuntimeOptions): QueryHostResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.param)) {
    query['Param'] = request.param;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'QueryHost',
    version = '2016-07-12',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function queryHost(request: QueryHostRequest): QueryHostResponse {
  var runtime = new Util.RuntimeOptions{};
  return queryHostWithOptions(request, runtime);
}

model UpdateHostRequest {
  param?: string(name='Param'),
}

model UpdateHostResponseBody = {
  code?: string(name='Code', description='code of the request'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId', description='Id of the request'),
  success?: boolean(name='Success'),
}

model UpdateHostResponse = {
  headers: map[string]string(name='headers'),
  body: UpdateHostResponseBody(name='body'),
}

async function updateHostWithOptions(request: UpdateHostRequest, runtime: Util.RuntimeOptions): UpdateHostResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.param)) {
    query['Param'] = request.param;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'UpdateHost',
    version = '2016-07-12',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function updateHost(request: UpdateHostRequest): UpdateHostResponse {
  var runtime = new Util.RuntimeOptions{};
  return updateHostWithOptions(request, runtime);
}

